package quickSort;

import java.util.Arrays;

public class QuickSort {

    public static void main(String[] args) {
        QuickSort quickSort = new QuickSort();
        int [] a = {-5,6,3,8,9,-21,23,1,2};
        quickSort.sort(a,0,a.length-1);
    }

    public void sort(int[] array,int left,int right){
        if(left > right){
            return;
        }
        int i = left;
        int j = right;
        int base = array[left];

        while (i<j){
            while (i<j && base<=array[j]){
                j--;
            }
            while (i<j && base>=array[i]){
                i++;
            }

            int temp = array[j];
            array[j] = array[i];
            array[i] = temp;

        }
        array[left] = array[i];
        array[i] = base;

        sort(array,left,i-1);
        sort(array,i+1,right);
        System.out.println("Sorting: " + Arrays.toString(array));
    }

}
